Skip to content

fix(id-web): validate shell contract field specs - #4238

Merged
dezren39 merged 3 commits into
mainfrom
queue/5412-2657-shell-contract-validation
Nov 2, 2026
Merged

dezren39 merged 3 commits into
mainfrom
queue/5412-2657-shell-contract-validation

Conversation

@dezren39

@dezren39 dezren39 commented Nov 2, 2026 •

Copy link
Copy Markdown
Member

Summary

- JSON.parse(text) as ShellContract
+ parseShellContract(text)
  • Validate every client/server frame field spec at load; errors identify the frame and field.
  • Convert malformed specs into failed frame checks so Conformance records a violation instead of throwing.
  • Add load/checker/session regressions. Existing view fixtures now include the contract-required view_revision.

Evidence

  • Before: clean main, bun run test -- src/world-contract.test.ts — 3 existing failures from missing view_revision.
    After: same command — 20/20 tests pass.
  • bun run typecheck still reports the pre-existing nullability error at src/image-upload.test.ts:423, reproduced on clean main.
  • git diff --check — pass.

Merge Danger

Door: two-way

Blast Radius: low — checker behavior and its tests only; no wire-format changes.

Closes #2657.


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need.

@dezren39
dezren39 requested a review from a team as a code owner November 2, 2026 06:51
@coderabbitai

coderabbitai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 50 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f2c7b81c-e7f6-41b3-bd41-5e4c98d5454d
Commits

Reviewing files that changed from the base of the PR and between 9456d01 and 04af08e.

Files selected for processing: 2
  • pkgs/id/web/src/shell-contract.ts
  • pkgs/id/web/src/world-contract.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T10:17:33.569887Z 04af08e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c2319ed9a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

min: raw.min as number | undefined,
max: raw.max as number | undefined,
maxBytes: raw.max_bytes as number | undefined,
allowed: raw.enum as string[] | undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate constraint types before accepting field specs

When a contract contains a malformed constraint such as chat.text: {"type":"string","enum":7}, the new parseShellContract accepts it because this assertion performs no runtime validation. Passing the returned contract to checkClientFrame with a chat message then throws TypeError: field.allowed.includes is not a function, bypassing the failed-check handling and preventing Conformance from recording a violation. Validate the constraint types during parsing, particularly that enum is an array of strings, so successfully loaded contracts cannot reach this failure.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 04af08e: parseField now validates constraint types at load — enum must be an array of strings, and min/max/max_bytes must be finite numbers — so parseShellContract rejects a malformed spec with the frame.field prefix instead of letting checkValue throw later. Regression tests added ("rejects malformed constraint values when loading a contract"); bun run test -- src/world-contract.test.ts passes 21/21 on the laptop.

parseField accepted malformed constraints (e.g. enum: 7) unchecked, so a
loaded contract could make checkValue throw (allowed.includes) instead of
recording a violation. Reject non-finite min/max/max_bytes and non-string-array
enum at parse time; regression tests cover both. Addresses Codex P2 on PR #4238.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant